package 代码记录.指定公司代码练习记录.面试手撕2024;

import java.util.*;

public class Test {
    /**
     * 给定一个String，eg:01-02-03-04-05-06-07 输出2
     * 合法的字符通过- 或者：链接
     * 包含0-9、a-f、A-F - 不区分大小写，所以得去重，字符合法性校验
     * 输出得"01"必须得是两个字符
     * 给一个字符串，输出去重后合法得mac地址数
     */
    public static void main(String[] args) {
        String str = "01-02-0A-04-05-06-07";
        String[] temp = str.split("-");
        List<String> list = new ArrayList<>();
        List<String> res = new ArrayList<>();
        System.out.println(Arrays.toString(temp));
        for(int i = 0;i < temp.length;i++){
            if(temp[i].length() == 2){
                list.add(temp[i]);
            }
        }
        System.out.println(list.toString());
        for (String s : list) {
            String s1 = "";
            for(int i = 0;i < s.length();i++){
                if(Character.isLetter(s.charAt(i))){
                    char c = Character.toLowerCase(s.charAt(i));
                    s1 += c;
                }else{
                    s1 += s.charAt(i);
                }
            }
            res.add(s1);
        }
        int ans = helper(temp);
        System.out.println(ans);

    }
    private static int helper(String[] str){
        Set<String> set = new HashSet<>();
        StringBuilder sb = new StringBuilder();
        for(int left = 0,right = 0;right < str.length;right++){
            if(right - left + 1 == 6){
                set.add(sb.toString());
                left++;
            }else{
                sb.append(str[right]).append("-");
            }
        }
        return set.size();
    }
}
